/*
 * @Author: lvgrape lvgrape@outlook.com
 * @Date: 2024-06-20 16:41:51
 * @LastEditors: LVGRAPE
 * @LastEditTime: 2024-07-08 15:26:19
 * @FilePath: \zino_premium_rt\ZINO\acceleration\acceleration.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#ifndef __ZINO_ACCC_H_
#define __ZINO_ACCC_H_
#include <stdint.h>
#include "maths.h"

#define ACC_CALIBRATION_COUNT 32
struct cali_face_range
{
    i16_vector_t range[6];
};
struct acc_device
{
    void *user_data;
    i16_vector_t adc;
    i16_vector_t offset; // 6-face calibration
    i16_vector_t zero;   // level calibration
    i16_vector_t up;
    i16_vector_t down;
    int16_t varinace_limit;
    int16_t acc_1G;//adc value at 1G
    fp_vector_t value;// value g
    fp_vector_t value_lpf;
    float scale_factor;//adc to value
    int16_t sample_count;
    uint8_t cali_face;
    uint8_t calibrated_face;
    uint8_t onCaliRgbCnt;
    int16_t traceBuffer[ACC_CALIBRATION_COUNT];
    struct cali_face_range faceRange;
    struct math_variance_i16 variance;
    int (*init)(struct acc_device *dev);
    int (*get_raw_data)(int16_t *gx);
    int (*perform_6_face_calibration)(struct acc_device *dev);
    int (*update)(struct acc_device *dev);
};

void acc_6face_calibration_key_handle(uint8_t times);


#endif // !__ZINO_ACCC_H_

